﻿namespace mycalendar
{
    internal class Program
    {
        /// <summary>
        /// 输出2022年日历
        /// </summary>
        /// <param name="args"></param>
        static void Main(string[] args)
        {
            const int monthHeight = 10, monthWidth = 30, dayWidth = 4;
            DateTime startday = new DateTime(2021, 12, 26);
            DateTime endday = new DateTime(2022, 1, 1);
            int x = 0, y = 0;
            for (int month = 1; month < 13; month++)
            {
                x = (month - 1) % 3 * monthWidth;
                y = (month - 1) / 3 * monthHeight;
                Console.SetCursorPosition(x, y);
                Console.WriteLine($"{month}月");
                Console.SetCursorPosition(x, y + 1);
                Console.WriteLine("  日  一  二  三  四  五  六");
                do
                {
                    TimeSpan timeSpan = endday - startday;
                    int thedayofweek = (int)(timeSpan.TotalDays % 7);
                    Console.SetCursorPosition(x + 4 * thedayofweek, y + 2);
                    Console.WriteLine(endday.Day.ToString().PadLeft(4));
                    if (thedayofweek == 6)
                        y++;
                    endday = endday.AddDays(1);
                } while (endday.Month == month);
            }
            Console.ReadKey();
        }
    }
}